package cn.neusoft.controller;


import cn.neusoft.po.ProductDetail;
import cn.neusoft.service.IProductDetailService;
import cn.neusoft.vo.ResponseObj;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hxj
 * @since 2023-12-27
 */
@RestController
@RequestMapping("/productDetail")
public class ProductDetailController {

    @Autowired
    IProductDetailService service;

    @PostMapping
    public ResponseObj saveOrUpdate(@RequestBody ProductDetail productDetail){
        boolean b = service.saveOrUpdate(productDetail);
        return b? ResponseObj.SUCCESS():ResponseObj.ERROR(90001,"保存商品详情信息失败");
    }

    @GetMapping("/{id}")
    public ResponseObj getByPid(@PathVariable("id") Integer pid){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("product_id",pid);
        ProductDetail productDetail = service.getOne(queryWrapper);
        if (productDetail==null){
            return ResponseObj.ERROR(90002,"没有商品详情信息");
        }
        return ResponseObj.SUCCESS(productDetail);
    }
    
}
